<script>
	import {
		mapstate,
		mapMutations
	} from 'vuex';
	export default {
		onLaunch: function() {
			
		},
		onShow: function() {
			this.loginByToken()
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods:{
			...mapMutations(['login']),
			async loginByToken() {
				let token = ''
				uni.getStorage({
				    key: 'token',
				    success: function (res) {
				        token = res.data
				    }
				});
				if (token == undefined) {
					return 
				}
				const res = await this.$myRequest({
					url: '/user/token/login',
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						"token": token
					}
				});
				// console.log(res)
				if (res.data.code == 0) {
					if (res.data.data == null) {
						// console.log('=====')
						return
					}
					// console.log('------')
					this.login(res.data.data)
				}
			}
		}
	}
</script>

<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "uview-ui/index.scss";
	// .page{
	// 	width: 100%;
	// 	height: 100%;
	// 	background-color: #f0f0f0;
	// 	position: absolute;
	// }
</style>
